#!/bin/bash
# Author: fanyongfeng
# 59 23 * * * /bin/bash /root/script/mysql_log_backup.sh &>> /backup/mysql_log_backup/backup.log

TODAY=$(date +%Y%m%d)
BACKUP_DIR="/backup/mysql_log_backup"
BASE_DIR="/data/mysql-5.7.35"
LOG_FILE_PATH="${BASE_DIR}/logs/general.log"

mkdir -p ${BACKUP_DIR}
\cp -p ${LOG_FILE_PATH} ${BACKUP_DIR}/general.log.${TODAY}
cd ${BACKUP_DIR} && gzip -f general.log.${TODAY} && truncate -s 0 ${LOG_FILE_PATH}

find ${BACKUP_DIR} -type f -mtime +180 -name "general.log*.gz" | xargs -r -n 10 rm -f

